package com.lzb.browser.activity;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.lzb.browser.BaseAc;
import com.lzb.browser.Content;
import com.lzb.browser.R;
import com.lzb.browser.databinding.ActivityEnablePwdBinding;
import com.lzb.browser.basic.utils.SPUtil;
import com.blankj.utilcode.util.ToastUtils;

public class EnablePwdActivity extends BaseAc<ActivityEnablePwdBinding> implements View.OnClickListener {


    @Override
    protected int onCreate() {
        return R.layout.activity_enable_pwd;
    }

    @Override
    protected void initView() {
        mDataBinding.ivEnablePwdBack.setOnClickListener(view -> getOnBackPressedDispatcher().onBackPressed());

        // 设置启用/关闭图案密码的点击事件
        mDataBinding.llNotEnable.setOnClickListener(this);
        mDataBinding.llEnabled.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.llNotEnable) {//启用图案密码
            enablePatternPassword();
        } else if (id == R.id.llEnabled) {//关闭图案密码
            disablePatternPassword();
        }
    }

    @Override
    protected void initData() {
        // 初始化图案密码状态
        updatePasswordState();
    }

    /**
     * 启用图案密码
     */
    private void enablePatternPassword() {
        SPUtil.putBoolean(mContext, Content.isEnablePassword, true);
        updatePasswordState();
    }

    /**
     * 关闭图案密码
     */
    private void disablePatternPassword() {
        SPUtil.putBoolean(mContext, Content.isEnablePassword, false);
        updatePasswordState();
    }

    /**
     * 更新图案密码状态显示
     */
    private void updatePasswordState() {
        boolean isEnabled = SPUtil.getBoolean(mContext, Content.isEnablePassword, false);

        if (isEnabled) {
            // 已启用状态
            mDataBinding.ivEnable.setVisibility(View.VISIBLE);
            mDataBinding.ivNotEnable.setVisibility(View.GONE);
            mDataBinding.tvEnabled.setTextColor(Color.parseColor("#BF96FF"));
            mDataBinding.tvNotEnable.setTextColor(Color.parseColor("#333333"));
        } else {
            // 未启用状态
            mDataBinding.ivEnable.setVisibility(View.GONE);
            mDataBinding.ivNotEnable.setVisibility(View.VISIBLE);
            mDataBinding.tvEnabled.setTextColor(Color.parseColor("#333333"));
            mDataBinding.tvNotEnable.setTextColor(Color.parseColor("#BF96FF"));
        }
    }
}